package com.smartstate.IOC.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartstate.IOC.entity.DeviceCarePlan;
import com.smartstate.IOC.entity.EquipMent;
import com.smartstate.IOC.vo.MoudelEquipmentVo;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface EquipmentMapper extends BaseMapper<EquipMent> {

    @Select(" <script> select mdl.id moudel_id, mdl.`name` moudel_name, mdl.type obj_type, mdl.parentId moudel_parent_id, mil.deviceId device_id, eqp.type equipment_type, eqp.`name` equipment_name , eqpType.`name`  equipment_type_name \n" +
            "from objmoudel mdl LEFT JOIN objmiddle mil on mdl.id = mil.objId \n" +
            "LEFT JOIN equipment eqp on mil.deviceId = eqp.deviceId\n" +
            "LEFT JOIN equipment_type eqpType on eqpType.id= eqp.type\n" +
            "where 1=1  <if test=\"type !=null and  type != '' \"> and mdl.type = #{type}  </if>  <if test=\"targetObjIds !=null and  targetObjIds.size != 0 \">\n" +
            " and mdl.id in\n" +
            " <foreach item=\"id\" index=\"index\" collection=\"targetObjIds\" open=\"(\" separator=\",\" close=\")\">\n" +
            "   #{id}\n" +
            "  </foreach>\n" +
            " </if>  </script>")
    List<MoudelEquipmentVo> getMoudelEquipments(@Param("type") String type, @Param("targetObjIds") List<String> targetObjIds);

    @Select(" select mdl.id moudel_id, mdl.`name` moudel_name, mdl.parentId moudel_parent_id, mdl.type obj_type \n" +
            "from objmoudel mdl where mdl.type = #{type} ")
    List<MoudelEquipmentVo> getMoudels(@Param("type") String type);


    @Select(" select deviceId device_id, deviceName device_name, careTime care_time from device_care_plan where careTime > now() order by careTime  ")
    List<DeviceCarePlan> getEquipmentCarePlans();

    @Select("select\n" +
            " CASE groupType WHEN \"1\" THEN \"锅炉组\" WHEN \"2\" THEN \"电气组\" WHEN  \"3\" THEN \"暖通组\" else \"\" END groupName ,\n" +
            "  GROUP_CONCAT(staffName) teamCountNum \n" +
            "from team  GROUP BY groupType;")
    List<Map<String, Object>> getTeamCountInfos();

    @Select("select count(type) from equipment  where type = 1 ")
    Integer getDeviceVidio();

    @Select("select * from equipment  where type =18")
    List<EquipMent> findAll();


    @Select("select * from equipment  where type =1")
    List<EquipMent> getDeviceVidioTotal();

    @Select("select * from equipment  where deviceId = #{cameraId}")
    EquipMent getChannelIdByCameraId(@Param("cameraId") String cameraId);

    @Select("select count(*) from equipment where  type = 1 ")
    Integer getAlarmEvent();
}
